//index.js
//获取应用实例
const app = getApp()
const myRequest=require("../../utils/require.js")

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    panyuan_index:"1",//1 主推盘源  2最新盘源
    top:[],
    newList:[],
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    app.GetUser().then(res=>{
      console.log('得到user',res)
      this.setData({
        userInfo:res
      })
    })
     
   //主推房源   
    myRequest.myRequest('DisSource/top',{},'GET').then(
      res=>{
       if(res.code===0){
         this.setData({top:res.data})
       }
      }
    )
    //最新房源
    myRequest.myRequest('DisSource/newList', {}, 'GET').then(
      res => {
        if (res.code === 0) {
          this.setData({ newList: res.data })
        }
      }
    )

  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  /**
   * 搜索结果
   */
  search:function(e){
    console.log(e.detail)
    wx.navigateTo({
      url: '/pages/panyuan-list/panyuan-list?search_key='+e.detail,

    })
  },
  /**
   * 切换盘源
   */
  changePanyuan:function(e){
   this.setData({
     panyuan_index: e.currentTarget.dataset.index
   })
  },
  ToDetail(e){
   
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  }
})
